<?php
/**
 * Created by PhpStorm.
 * User: LENOVO
 * Date: 2018/9/15
 * Time: 20:33
 */

namespace app\wx\model;


use think\Model;

class XcxUserInfo extends Model
{
  protected $hidden = ['openid', 'session_key', 'create_time', 'update_time'];
  protected $autoWriteTimestamp = 'datetime';

  public function historyList()
  {
    return $this->hasMany('History', 'userId', 'id')->order('update_time desc');
  }

  public function collection()
  {
    return $this->hasMany('Collection', 'userId', 'id')->order('update_time desc');
  }

  public static function getBuyUserId($id)
  {
    $result = self::with(['historyList', 'historyList.house'])
        ->find($id);
    return $result;
  }

  public static function getCollectionById($id){
    $result = self::with(['collection', 'collection.house'])
        ->find($id);
    return $result;
  }
}